package Vista;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;

import Controlador.cCategoria;
import Controlador.cCompras;
import Modelo.Conexion;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Compras extends javax.swing.JDialog {
	private JButton jButton1;
	private JLabel jLabel5;
	private JLabel jLabel1;
	private JTextField jTextField1;
	private JComboBox jComboBox1;
	private JLabel jLabel2;
	private JLabel jLabel3;
	private JTextField jTextField2;
	private JLabel jLabel4;
	private JPanel jPanel1;
	private JButton jButton3;
	private JButton jButton2;

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				Compras inst = new Compras(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public Compras(JFrame frame) {
		super(frame);
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				this.addWindowListener(new WindowAdapter() {
					public void windowOpened(WindowEvent evt) {
						System.out.println("this.windowOpened, event="+evt);
						//TODO add your code for this.windowOpened
						new Conexion().llenarCombo(jComboBox1, "select \"Descripcion\" from \"Ingredientes\" ");
						cCompras cComp = new cCompras(); 
						cComp.limpiar(jLabel4,jTextField1,jComboBox1,jTextField2,jButton1,jButton2,jButton3);
					}
				});
				{
					jButton1 = new JButton();
					getContentPane().add(jButton1);
					jButton1.setText("Incluir");
					jButton1.setBounds(63, 225, 86, 22);
					jButton1.setFont(new java.awt.Font("Segoe UI",0,9));
					jButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButton1.actionPerformed, event="+evt);
							//TODO add your code for jButton1.actionPerformed
							cCompras cComp = new cCompras(); 
							cComp.guardar(jLabel4,jTextField1,jComboBox1,jTextField2,jButton1,jButton2,jButton3);
							
						}
					});
				}
				{
					jButton2 = new JButton();
					getContentPane().add(jButton2);
					jButton2.setText("Cancelar");
					jButton2.setBounds(148, 225, 86, 22);
					jButton2.setFont(new java.awt.Font("Segoe UI",0,9));
					jButton2.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButton2.actionPerformed, event="+evt);
							//TODO add your code for jButton2.actionPerformed
							cCompras cComp = new cCompras(); 
							cComp.limpiar(jLabel4,jTextField1,jComboBox1,jTextField2,jButton1,jButton2,jButton3);
						}
					});
				}
				{
					jButton3 = new JButton();
					getContentPane().add(jButton3);
					jButton3.setText("Salir");
					jButton3.setBounds(288, 225, 77, 22);
					jButton3.setFont(new java.awt.Font("Segoe UI",0,9));
					jButton3.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButton3.actionPerformed, event="+evt);
							//TODO add your code for jButton3.actionPerformed
							dispose();
						}
					});
				}
				{
					jPanel1 = new JPanel();
					getContentPane().add(jPanel1);
					jPanel1.setBounds(38, 75, 365, 127);
					jPanel1.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					jPanel1.setLayout(null);
					{
						jLabel4 = new JLabel();
						jPanel1.add(jLabel4);
						jLabel4.setText("jLabel4");
						jLabel4.setBounds(306, 56, 45, 16);
					}
					{
						jTextField2 = new JTextField();
						jPanel1.add(jTextField2);
						jTextField2.setBounds(110, 87, 73, 22);
					}
					{
						jLabel3 = new JLabel();
						jPanel1.add(jLabel3);
						jLabel3.setText("Cantidad:");
						jLabel3.setBounds(21, 87, 77, 20);
					}
					{
						jLabel2 = new JLabel();
						jPanel1.add(jLabel2);
						jLabel2.setText("Ingrediente:");
						jLabel2.setBounds(21, 54, 77, 20);
					}
					{
						ComboBoxModel jComboBox1Model = new DefaultComboBoxModel(new String[] { "Item One", "Item Two" });
						jComboBox1 = new JComboBox();
						jPanel1.add(jComboBox1);
						jComboBox1.setModel(jComboBox1Model);
						jComboBox1.setBounds(110, 54, 184, 20);
						jComboBox1.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								System.out.println("jComboBox1.actionPerformed, event="+evt);
								//TODO add your code for jComboBox1.actionPerformed
								try
								{
									int n=Integer.parseInt( new Conexion().getCampo("Ingredientes", "\"Descripcion\"='"+ jComboBox1.getSelectedItem() +"'").toString());
									jLabel4.setText(""+n);
									
								}
								catch(Exception e)
								{
									
								}
								
							}
						});
					}
					{
						jTextField1 = new JTextField();
						jPanel1.add(jTextField1);
						jTextField1.setBounds(110, 23, 73, 21);
					}
					{
						jLabel1 = new JLabel();
						jPanel1.add(jLabel1);
						jLabel1.setText("Codigo:");
						jLabel1.setBounds(21, 21, 77, 20);
					}
				}
				{
					jLabel5 = new JLabel();
					getContentPane().add(jLabel5);
					jLabel5.setText("Compra de Ingredientes");
					jLabel5.setBounds(38, 37, 277, 26);
					jLabel5.setFont(new java.awt.Font("Segoe UI",1,18));
				}
			}
			this.setSize(445, 307);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
